# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=erdtree
pkgver=2.0.0
pkgrel=2
pkgdesc='A multi-threaded filesystem and disk-usage analysis tool'
arch=('loong64' 'x86_64')
url='https://github.com/solidiquis/erdtree'
license=('MIT')
depends=('glibc' 'gcc-libs')
makedepends=('git' 'rust')
#options=('!lto')
_commit='b72c9f9e0bc146b6b551e50d7649b19050f77543'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # download dependencies
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "$pkgname"

  cargo build --frozen --release --all-features

  # completions
  cd target/release
  for shell in bash fish zsh; do
    ./erd --completions "$shell" > "$shell-completion"
  done

}

check() {
  cd "$pkgname"

  cargo test --frozen --all-features
}

package() {
  cd "$pkgname"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" target/release/erd

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
  cp -vr assets "$pkgdir/usr/share/doc/$pkgname"

  # completions
  pushd target/release
  install -vDm644 bash-completion "$pkgdir/usr/share/bash-completion/completions/erd"
  install -vDm644 fish-completion "$pkgdir/usr/share/fish/vendor_completions.d/erd.fish"
  install -vDm644 zsh-completion "$pkgdir/usr/share/zsh/site-functions/_erd"
  popd

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
